<?php
/*
* Description: Create all custom fields in custom post type agents.
* Version: 1.0
* Author: huuducvt
* Author URI: http://zonthemes.com/author/huuducvt
*/

add_action('admin_menu' ,'zontheme_agents_metaboxes');
add_action('save_post', 'zontheme_agents_metaboxes_save');


function zontheme_agents_metaboxes() {
	add_meta_box('zonthemes_agents_metabox', 'Agents Information', 'zontheme_agents_metaboxes_view', 'agents', 'normal', 'high' );
}

function zontheme_agents_metaboxes_view() {
	global $post;
	include('zonthemes-agents-metaboxes-view.php');
}

function zontheme_agents_metaboxes_save($post_id) {
	global $post;
	if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; }
	if(isset($_POST['post_type'])) {
		if('page' == $_POST['post_type']) {
			if(!current_user_can('edit_page', $post_id)) { return $post_id; }
			if(!current_user_can('edit_post', $post_id)) { return $post_id; }
		}
	}
	if(isset($_POST['zon_agents_staff'])) { update_post_meta($post_id, 'zon_agents_staff', htmlspecialchars($_POST['zon_agents_staff'])); } 
	if(isset($_POST['zon_agents_email'])) { update_post_meta($post_id, 'zon_agents_email', htmlspecialchars($_POST['zon_agents_email'])); } 
	if(isset($_POST['zon_agents_phone'])) { update_post_meta($post_id, 'zon_agents_phone', htmlspecialchars($_POST['zon_agents_phone'])); } 
	if(isset($_POST['zon_agents_address'])) { update_post_meta($post_id, 'zon_agents_address', htmlspecialchars($_POST['zon_agents_address'])); } 
}
?>